<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增课程</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }

        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 20px;
        }

        .form-container {
            max-width: 600px;
            margin: 20px auto;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }

        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        .form-group input,
        .form-group textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }

        .form-group textarea {
            height: 100px;
            resize: vertical;
        }

        .form-buttons {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
            margin-top: 20px;
        }

        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }

        .btn-secondary {
            background-color: #ccc;
            color: #333;
        }
    </style>
</head>
<body>
<h1>新增课程</h1>

<div class="form-container">
    <form id="addCourseForm">
        <div class="form-group">
            <label for="courseName">课程名称:</label>
            <input type="text" id="courseName" name="cname" required>
        </div>

        <div class="form-group">
            <label for="courseDescription">简介:</label>
            <textarea id="courseDescription" name="mark" required></textarea>
        </div>

        <div class="form-group">
            <label for="teacherName">任课教师:</label>
            <input type="text" id="teacherName" name="tea" required>
        </div>

        <div class="form-buttons">
            <button type="button" class="btn btn-secondary" onclick="cancelAdd()">取消</button>
            <button type="submit" class="btn btn-primary" onclick="courseAdd()">保存</button>
        </div>
    </form>
</div>

<script src="/js/jquery.min.js"></script>
<script>
    // 提交表单
    function courseAdd() {
        $.ajax({
            type: "POST",
            url: "/course/save",
            data: $("#addCourseForm").serialize(),
            success: function (data) {
                if (data == 1) {
                    alert("添加成功");
                    window.location.href = "/course/view";
                } else {
                    alert("添加失败");
                }
            }
        });
    }
   function cancelAdd() {
       window.location.href = "/course/view";
   }
</script>
</body>
</html>
